#include "LCD_3200.h"
#include "USART_3200.h"

#define F_CPU 16E6         // CPU clock speed for delay.h
#include <util/delay.h>

/*
 * build_heart
 * Purpose: To build a heartbeat icon on the LCD
 * Parameters: None
 * Returns: None
 */
void build_heart(void){
	usart_send_data(0xF8);	//define character 1
	usart_send_data(0);		//-----
	usart_send_data(0);		//-----
	usart_send_data(10);	//-*-*-
	usart_send_data(31);	//*****
	usart_send_data(31);	//*****
	usart_send_data(14);	//-***-
	usart_send_data(4);		//--*--
	usart_send_data(0);		//-----
	_delay_ms(15);		//delay to allow transfer
}

/*
 * build_antennaSignal
 * Purpose: To build an antenna signal on the LCD for Enabled or Disabled
 * Parameter: None
 * Returns: None
 */
void build_antennaSignal(void){
	//build the antenna on signal
	usart_send_data(0xFA);	//define character 3
	usart_send_data(1);		//    *
	usart_send_data(1);		//    *
	usart_send_data(1);		//    *
	usart_send_data(5);		//  * *
	usart_send_data(5);		//  * *
	usart_send_data(5);		//  * *
	usart_send_data(21);	//* * *
	usart_send_data(21);	//* * *
	_delay_ms(15);			//delay for send
	
	//build the antenna off signal
	usart_send_data(0xFC);	//define character 5
	usart_send_data(0);		//
	usart_send_data(0);		//
	usart_send_data(0);		//
	usart_send_data(0);		//
	usart_send_data(0);		//
	usart_send_data(0);		//
	usart_send_data(16);	//*
	usart_send_data(16);	//*
	_delay_ms(15);			//delay for send
}

// display the welcome screen on the LCD
void display_welcome(void){
	usart_send_data(0x0C);
	_delay_ms(60);
	gotoxy(0,0);
	usart_send_data('C');
	usart_send_data('E');
	usart_send_data('3');
	usart_send_data('2');
	usart_send_data('0');
	usart_send_data('0');
	usart_send_data(' ');
	usart_send_data('R');
	usart_send_data('F');
	usart_send_data('I');
	usart_send_data('D');
	gotoxy(1,0);
	usart_send_data('W');
	usart_send_data('E');
	usart_send_data('L');
	usart_send_data('C');
	usart_send_data('O');
	usart_send_data('M');
	usart_send_data('E');
	usart_send_data('!');
}


/*
 * INIT_LCD
 * Purpose: Initialize the LCD
 * Parameters: None
 * Returns: None
 */
void INIT_LCD(void){
	//initialize the BAUD rate
	set_baud((uint16_t)LCD_VALUE);
	//turn off the cursor blink
	usart_send_data(0x16);
	//clear the lcd of any data
	usart_send_data(0x0C);
	//delay for the LCD to Clear
	_delay_ms(60);
	//Build Custom Characters
	build_heart();
	build_antennaSignal();
}

// Moves to a specific location on the LCD panel
void gotoxy(unsigned char row, unsigned char column){
	if(row == 0)
	usart_send_data(0x80 + column);
	if(row == 1)
	usart_send_data(0x94 + column);
}